/**
  ******************************************************************************
  * @file   : define.h
  * @author : 测试1组（houtiezhu）
  * @version: v0
  * @date   : 2019.07.09
  * @brief  : 
  *           
  * Copyright (C) 2019  Hangzhou SDIC Microelectronics Co., Ltd
  ******************************************************************************
**/

#ifndef define_H
#define define_H

/*系统头文件包含*/
#include "YinXing.h"

#define u8  uint8_t 
#define u16 uint16_t
#define u32 uint32_t


#define uint8  uint8_t 
#define uint16 uint16_t
#define uint32 uint32_t



typedef	struct
{
	uint8_t rec		:1;			
	uint8_t tran	:1;			
	uint8_t recOver :1;	
 
}stateFlag_typedef;	

extern stateFlag_typedef stateFlag;
extern uint8_t spi_rec_Byte[20];
extern uint8_t spi_rec_data[20];
extern uint8_t spi_Byte_num;
extern uint8_t spi_data_num;

//用户头文件包含

extern uint8_t ReceiveData[20];
extern uint8_t ReceiveFlag;
extern uint16_t Cnt;

#define SCK_1     	GPIO_SetBits(GPIO3,GPIO_Pin_0)
#define SCK_0     	GPIO_ResetBits(GPIO3,GPIO_Pin_0)

#define DATA_1     	GPIO_SetBits(GPIO3,GPIO_Pin_2)
#define DATA_0     	GPIO_ResetBits(GPIO3,GPIO_Pin_2)
#define READ_DATA	GPIO_ReadInputDataBit(GPIO3,GPIO_Pin_2)

 
//spi发送数据引脚设置
#define SDO_0           (GPIO2->ODR &= ~(1<<5))
#define SDO_1           (GPIO2->ODR |= (1<<5))

//spi接收引脚设置
#define SDI_rec         (GPIO2->IDR &= (1UL<<6))
#define CS_rec          (GPIO2->IDR &= (1UL<<7))
#define SCK_rec         (GPIO2->IDR &= (1UL<<1))



extern uint8_t over_rec_flag;


uint8_t SPI_ReveiceByte(void);
void SPI_SendByte(uint8_t data);
void GPIO_SPI_Init(void);
void delay_ms(uint16_t a);
void EXIT_IRQ_Init(void);
void Spi_send_data(uint8_t senddata);


//=========================AKY BP=======================================================

typedef union byte_bit 
	{
		struct 
		{ 
			uint8 bit0:1; 
			uint8  bit1:1; 
			uint8  bit2:1; 
			uint8  bit3:1; 
			uint8  bit4:1; 
			uint8  bit5:1; 
			uint8  bit6:1; 
			uint8  bit7:1;
		}bt;
		uint8    b;
	}byte_bit;
typedef union word_data
{
	uint16 	w;
	uint8 	b[2];
}word_data;
typedef union dword_data 
{
	uint32    l;
	uint16 	w[2];
	uint8 	b[4];
}dword_data;

extern union byte_bit					MeasureStateFlag;    
#define   SamplePressure		MeasureStateFlag.bt.bit0 
#define   SampleSignal  		MeasureStateFlag.bt.bit1 

extern union byte_bit					STATEFlag1; 
#define   First30mmHg  			STATEFlag1.bt.bit0  
#define   MemoryMode				STATEFlag1.bt.bit1  
#define   RePump   					STATEFlag1.bt.bit2
#define   GetLeakagePresureFlag	STATEFlag1.bt.bit3
#define   MemoryFull				STATEFlag1.bt.bit4 
#define   FirstDeflate  		STATEFlag1.bt.bit5

extern union byte_bit					OneShotFlag;             
#define   OneShot 					OneShotFlag.bt.bit0   
#define   OneShotDC					OneShotFlag.bt.bit1   
#define   KeyIn 						OneShotFlag.bt.bit2            
#define   SecondFlag				OneShotFlag.bt.bit3     
#define   OneShotPump				OneShotFlag.bt.bit4 
#define   OneShotValve			OneShotFlag.bt.bit5
#define   OneShotRX					OneShotFlag.bt.bit6   
  
extern union byte_bit					initstates; 
#define   SmallSignalOn 		initstates.bt.bit0 
#define   NormalSignal  		initstates.bt.bit1 
#define   LargeSignalOn 		initstates.bt.bit2

   
extern union byte_bit					AlgoStateFlag;        
#define   HeartSign			AlgoStateFlag.bt.bit0 
#define   NormalResultCode	AlgoStateFlag.bt.bit1 
#define   RepumpCheckFlag		AlgoStateFlag.bt.bit2  
//#define   SX4      				AlgoStateFlag.bt.bit3 
#define   PeakFlag 					AlgoStateFlag.bt.bit4 
#define   FindFlag					AlgoStateFlag.bt.bit5 
#define   Thresnum1					AlgoStateFlag.bt.bit6 
#define   Thresnum2					AlgoStateFlag.bt.bit7 

extern union byte_bit					AlgorithmFlag;          
#define   AlgoFindMAPFlag		AlgorithmFlag.bt.bit0    
#define   AlgoSysOkFlag  		AlgorithmFlag.bt.bit1   
#define   AlgoDiaOkFlag  		AlgorithmFlag.bt.bit2    
#define   AlgoMAPOkFlag  		AlgorithmFlag.bt.bit3    
#define   AlgoOnePFlag   		AlgorithmFlag.bt.bit4  
#define   AlgoFirstPFlag 		AlgorithmFlag.bt.bit5   
#define   AlgoMaxPFlag   		AlgorithmFlag.bt.bit6   
#define   AlgoExchFlag			AlgorithmFlag.bt.bit7  

extern union byte_bit					SysStateFlag;            
#define   IsPowerOn					SysStateFlag.bt.bit0    
#define   IsAlgoEnd  				SysStateFlag.bt.bit1     
#define   IsCalibrate				SysStateFlag.bt.bit2 
#define   IsAlgorithm				SysStateFlag.bt.bit3    
#define   IsMinute					SysStateFlag.bt.bit4   	 
#define   IsShowResult			SysStateFlag.bt.bit5   
#define   IsShowPressure		SysStateFlag.bt.bit6    
#define   IsPump						SysStateFlag.bt.bit7 

extern union byte_bit					SysStateFlag2;  
#define   BTFlag 						SysStateFlag2.bt.bit0    
#define   IsCALMode					SysStateFlag2.bt.bit1  	
#define	  EepromNoSet				SysStateFlag2.bt.bit2  
#define	  ReadEepromError		SysStateFlag2.bt.bit3  
#define	  FirstPulse				SysStateFlag2.bt.bit4	
#define	  PADFlag						SysStateFlag2.bt.bit5	
#define	  VoiceStop					SysStateFlag2.bt.bit6	


extern union byte_bit					SystemSetFlag;        	   
#define	  PADEnable					SystemSetFlag.bt.bit0
#define	  TwoUser						SystemSetFlag.bt.bit1
#define   RCSensorType  		SystemSetFlag.bt.bit2 
#define   LinearValveFlag  	SystemSetFlag.bt.bit3	
#define	  PowerType					SystemSetFlag.bt.bit4
#define   AMPMLCD   				SystemSetFlag.bt.bit5 
#define   NoTimer 					SystemSetFlag.bt.bit6  	
#define	  UparmWWFlag				SystemSetFlag.bt.bit7

extern union byte_bit					SystemSetFlag2;
#define   InfDefFlag 				SystemSetFlag2.bt.bit0
#define   UnitSetEnable     SystemSetFlag2.bt.bit1
#define	  AverageType				SystemSetFlag2.bt.bit2
#define	  BLFlag						SystemSetFlag2.bt.bit3	
#define	  VoiceSetEnable		SystemSetFlag2.bt.bit4	
#define	  EndVoice					SystemSetFlag2.bt.bit5
#define	  BTIconEnable			SystemSetFlag2.bt.bit6
#define	  BTEnable					SystemSetFlag2.bt.bit7

extern union byte_bit					SystemSetFlag3;
#define	  UnitIcon					SystemSetFlag3.bt.bit0	
#define		CuffDetect					SystemSetFlag3.bt.bit1	
#define		AlarmClock				SystemSetFlag3.bt.bit2
#define	  E2Mode						SystemSetFlag3.bt.bit3
#define		SetMode2					SystemSetFlag3.bt.bit4
#define		LCDType						SystemSetFlag3.bt.bit5
#define		NoTimeSet					SystemSetFlag3.bt.bit6
#define		MoveDetect				SystemSetFlag3.bt.bit7

extern  uint8 VoiceFlag;	//多语种

extern union byte_bit					SystemSetFlag4;
#define	  BZEnable				SystemSetFlag4.bt.bit0
#define	  ShowMean				SystemSetFlag4.bt.bit1
#define		AUSMode					SystemSetFlag4.bt.bit2
#define		LCDType2				SystemSetFlag4.bt.bit3
#define		StartBZ					SystemSetFlag4.bt.bit4
#define		LCD80Y					SystemSetFlag4.bt.bit5
#define		DPIconDisable		SystemSetFlag4.bt.bit6
#define		UserSetEnable		SystemSetFlag4.bt.bit7

extern union byte_bit					SystemSetFlag5;
#define	  SendRomFlag				SystemSetFlag5.bt.bit0
#define		MemoryChangeFlag	SystemSetFlag5.bt.bit1

extern union byte_bit					SystemSetFlag6;
#define	  SendOKFlag				SystemSetFlag6.bt.bit0
#define	  ThreeKeyFlag			SystemSetFlag6.bt.bit1
#define	  SendMemoryFlag		SystemSetFlag6.bt.bit2
#define		ADOKFlag					SystemSetFlag6.bt.bit3
#define		functionOKFlag		SystemSetFlag6.bt.bit4
#define		AlarmFlag					SystemSetFlag6.bt.bit5
#define		AutoTestFlag			SystemSetFlag6.bt.bit6
#define		VoiceSetFlag			SystemSetFlag6.bt.bit7

extern union byte_bit					UserSetFlag;
#define	  mmHgkPaFlag				UserSetFlag.bt.bit0
#define	  VoiceEnable				UserSetFlag.bt.bit1
#define	  UserA							UserSetFlag.bt.bit2

extern union byte_bit					KeyFlag;
#define		KeyError					KeyFlag.bt.bit0
#define	  Key1							KeyFlag.bt.bit1
#define		Key2							KeyFlag.bt.bit2
#define		Key3							KeyFlag.bt.bit3

extern union byte_bit					MemorySetFlag;
#define HaveMemoryFirst			MemorySetFlag.bt.bit0	
#define HaveMemoryAvg				MemorySetFlag.bt.bit1
#define HaveMemoryAvg1			MemorySetFlag.bt.bit2
#define MemoryClredFlag			MemorySetFlag.bt.bit3
#define SetPressureOKFlag   MemorySetFlag.bt.bit4
#define CalScaleFirstFlag   MemorySetFlag.bt.bit5



extern union byte_bit					TimeBase;             
#define   T160Hz						TimeBase.bt.bit0 
#define   T80Hz							TimeBase.bt.bit1     
#define   T40Hz							TimeBase.bt.bit2 
#define   T20Hz							TimeBase.bt.bit3
#define   T10Hz							TimeBase.bt.bit4

extern union byte_bit					WatchTime;             
#define   T625ms						WatchTime.bt.bit0     
#define   T125ms 						WatchTime.bt.bit1    
#define   T250ms 						WatchTime.bt.bit2     
#define   T500ms 						WatchTime.bt.bit3    
#define   T1s	  						WatchTime.bt.bit4    
#define   T2s	  						WatchTime.bt.bit5     
#define   T4s   						WatchTime.bt.bit6    
#define   T8s	  						WatchTime.bt.bit7  
                   		
extern union byte_bit					Year;           
#define   YEAR0							Year.bt.bit0 
#define   YEAR1							Year.bt.bit1  
    
extern union	word_data				AutoOffTime2 ;        
#define	AutoOffTimew 				AutoOffTime2.w        
#define	AutoOffTime2b				AutoOffTime2.b[0]     
#define	AutoOffTime1b				AutoOffTime2.b[1]     

extern union	word_data				SensorCount;         
#define	 SensorCountw 			SensorCount.w        
#define	 SensorCount2b			SensorCount.b[0]    
#define	 SensorCount1b			SensorCount.b[1]  

extern union	word_data				ADCount ;         
#define	 ADCountw 					ADCount.w        
#define	 ADCount2b					ADCount.b[0]    
#define	 ADCount1b					ADCount.b[1]  

extern union	word_data				PressuremmHg;       
#define	 PressuremmHgw 			PressuremmHg.w       
#define	 PressuremmHg2b			PressuremmHg.b[0]   
#define	 PressuremmHg1b			PressuremmHg.b[1] 
extern union	word_data				OscilloSignal  ;       
#define	 OscilloSignalw  		OscilloSignal.w      
#define	 OscilloSignal02b		OscilloSignal.b[0]   
#define	 OscilloSignal01b		OscilloSignal.b[1] 

extern union	dword_data			Math;	       
#define	  Mathhw 						Math.w[0]            
#define	  Math04b						Math.b[0]            
#define	  Math03b						Math.b[1]            
#define	  Mathlw						Math.w[1]            
#define	  Math02b						Math.b[2]            
#define	  Math01b						Math.b[3] 

extern union	word_data				A1w;        
#define	A1 									A1w.w        
#define	A12b								A1w.b[0]     
#define	A11b								A1w.b[1] 
extern union	word_data				B1w;        
#define	B1 									B1w.w        
#define	B12b								B1w.b[0]     
#define	B11b								B1w.b[1]
extern union	word_data				C1w;        
#define	C1 									C1w.w        
#define	C12b								C1w.b[0]     
#define	C11b								C1w.b[1] 

extern union	word_data				ZeroCount;          
#define	 ZeroCountw 				ZeroCount.w          
#define	 ZeroCount2b				ZeroCount.b[0]       
#define	 ZeroCount1b				ZeroCount.b[1]  

extern union	word_data				SystolicValue;
#define	 SystolicValuew 		SystolicValue.w      
#define	 SystolicValue2b		SystolicValue.b[0]   
#define	 SystolicValue1b		SystolicValue.b[1]
  
extern union	dword_data			TemplateValue; 
#define	 TemplateValueLong	TemplateValue.l      
#define	 TemplateValuehw 		TemplateValue.w[0]   
#define	 TemplateValue04b		TemplateValue.b[0]   
#define	 TemplateValue03b		TemplateValue.b[1]   
#define	 TemplateValuelw 		TemplateValue.w[1]   
#define	 TemplateValue02b		TemplateValue.b[2]   
#define	 TemplateValue01b		TemplateValue.b[3] 
     

extern union	word_data				Xx;  		          
#define	  Xxw 							Xx.w                
#define	  Xx2b							Xx.b[0]              
#define	  Xx1b							Xx.b[1]             
          
extern union	word_data				Dy;    		
#define	  Dyw 							Dy.w                
#define	  Dy2b							Dy.b[0]              
#define	  Dy1b							Dy.b[1]   



















extern union 	byte_bit				mtemp0c,mtemp1c;
extern union 	byte_bit				IDbuffer;              
extern union 	byte_bit				ibuffer;  
extern union	word_data				PulseRam[63];  
extern union	word_data				PulsePressure[4];	


#define Enable 								1
#define Disable 							0


#define CALPressureLimit				500					//20mmHg
#define	SYSMargin								16;					//16mmHg		//20121002
#define	DIAMargin								10;					//10mmHg
#define	TimeMargin							180;  			//3??

extern uint8 ModifyFlag;
extern uint8 AllTimeFlag;
extern uint16 AUTOOFFTIME;
//#define AUTOOFFTIME							0x23				// Auto off time 0x2328=3min
#define TWO											0x003f			// 1.5sec TWO 
#define PUMPTIMEL								0x050a 			//0x02aa	PUMPTIME LONG 16 second 
#define PUMPTIMES								0x01ae			//0x00aa	 PUMPTIME SHORT 4 second 
#define PUMPTIMEP								30					// PUMPTIME Pressure 
#define SoundDelayValue					1000

//#define YEARINIT								19				// 2016 
#define MONTHINIT								1					// 1-1 
#define DAYINIT 								1					// 1:00
#define HOURINIT								0
#define MINUTEINIT							0

#define VerYear									21
#define	VerMonth								1
#define	VerDay									30


/*
#define ROM_MEMORY_Index 				//0xED00

#define	CalBak									//0xFE00
#define	CalAdd									//0xFE40
#define	FunctionBak							//0xFE80
#define	FunctionAdd							//0xFEC0

#define	UserBOffSet							//0x100
#define valveoffsetAdd					//0x3FB
#define	UserSetAdd							//0x1F1
#define	EEPROMCheckAdd					//0x1FE
#define	WorkModeAdd							//0x1FF
*/
#define RepumpOffset						//0x28				// repump addition pressure value:40mmHg 
#define	SpanValve								1						// sensor span
#define WHOSYS1									120
#define WHODIA1									80
#define WHOSYS2									130
#define WHODIA2									85
#define WHOSYS3									140
#define WHODIA3									90
#define WHOSYS4									160
#define WHODIA4									100
#define WHOSYS5									180
#define WHODIA5									110




#define	 VALVE									0x10				// VALVE 
#define  PUMP										0x20				// PUMP 
#define  POWER									0x40				// POWER 
#define  LBTVAL										0x80				// LBT 

#define  VALVEOFF								0x10			// VALVE off
#define  PUMPOFF 								0x20			// PUMP off
#define  POWEROFF								0x40			// POWER off
#define  LBTOFF									0x80			// LBT off

#define  A1UP										2865				//2980				//7513
#define  B1UP										2702				//2750
#define  C1UP										2412				//2350
#define  A1WW										2865				//2980
#define  B1WW										2702
#define  C1WW										2412

#define  A1UPR									6999
#define  A1WWR									6999


































#endif /* define_H */



/************************ (C) COPYRIGHT Hangzhou SDIC Microelectronics *****END OF FILE****/